<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js" type="text/javascript"></script>
    <title>WebSoket Demo</title>
    <script type="text/javascript">
        //验证浏览器是否支持WebSocket协议

        if (!window.WebSocket) {
            alert("WebSocket not supported by this browser!");
        }

        var ws;

        function display() {

            // -----  测试 IP  -----------

            //ws=new WebSocket("ws://192.168.1.113:8283/");
            //ws=new WebSocket("ws://192.168.1.113:8686/");
            ws=new WebSocket("ws://192.168.1.127:8686/");

            //监听消息
            ws.onmessage = function(event) {
                //valueLabel.innerHTML+ = event.data;
                log(event.data);
                //log(event);
            };

            // 打开WebSocket
            ws.onclose = function(event) {
                //WebSocket Status:: Socket Closed
            };
            // 打开WebSocket
            ws.onopen = function(event) {
                //WebSocket Status:: Socket Open
                //// 发送一个初始化消息
                ws.send("Test Login!");
            };
            ws.onerror =function(event){
                //WebSocket Status:: Error was reported
            };
        }

        var log = function(s) {
            if (document.readyState !== "complete") {
                log.buffer.push(s);
            } else {
                document.getElementById("contentId").innerHTML += (s + "\n");
                s = JSON.parse(s);
                document.getElementById("contentId").innerHTML += (s.data.message + "\n");
            }
        };


        function test(){
            // 用户反馈
            var param1 = $("#params1").val();
            var sendJson = '{"ActionType":"TEST","DataDictionary":{"param":"'+param1+'"}}';
            ws.send(sendJson);
        }

        function restaurantAdd(){
            // 商铺添加
            var sendJson = '{"ActionType":"event_restaurant_add","DataDictionary":{' +
                '"NAME":"商铺1",' +
                '"IMG_URL":"https://pic1.ajkimg.com/display/hj/3a071b2dbfdf6e589280d05e0f9113ba/240x180.jpg?t=1",'+
                '"DESCRIPTION":"描述",' +
                '"ANNOUNCEMENT":"公告内容",' +
                '"IS_OPENING":"1",' +
                '"OPENING_TIME":"9:30-12:00",' +
                '"OPENING_WEEK":"1,2,3,4,5",' +
                '"CONTACT_NAME":"张三",' +
                '"CONTACT_NUMBER":"15100008888",' +
                '"PROVINCE":"110000",' +
                '"CITY":"110100",' +
                '"COUNTY":"110110",' +
                '"DETAIL":"东码路28号",' +
                '"LNG":"110.50",' +
                '"LAT":"80.15"' +
                '}}';
            ws.send(sendJson);
        }

        function restaurantLogin(){
            // 商家登录
            var param1 = $("#params1").val();
            var sendJson = '{"ActionType":"event_restaurant_login","DataDictionary":{' +
                '"CONTACT_NUMBER":"15100008888",' +
                '"PASSWORD":""' +
                '}}';
            ws.send(sendJson);
        }

        function restaurantFoodGroupsAdd(){
            // 商家添加商品分类
            var param1 = $("#params1").val();
            var sendJson = '{"ActionType":"event_restaurant_food_groups_add","DataDictionary":{' +
                '"NAME":"分类1",' +
                '"DESCRIPTION":"点点"' +
                '}}';
            ws.send(sendJson);
        }

        function restaurantFoodAdd(){
            // 商家添加商品
            var param1 = $("#params1").val();
            var sendJson = '{"ActionType":"event_restaurant_food_add","DataDictionary":{' +
                '"FOOD_GROUPS_ID":"1",' +
                '"NAME":"商品1",' +
                '"IMG_URL":"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2390973038,561107391&fm=23&gp=0.jpg",' +
                '"PRICE":"12.50",' +
                '"IS_LIMIT":"1",' +
                '"LUNCHBOX_AMOUNTS":"2",' +
                '"LUNCHBOX_PRICE":"2.5",' +
                '"IS_ON_SELL":"1",' +
                '"STOCK_DAY":"100",' +
                '"STOCK_LEFT":"50",' +
                '"SPECIAL_FEATURE":"1",' +
                '"ORDER_UNIT":"份",' +
                '"ORDER_MINIMUM":"1",' +
                '"FOOD_PROPERTY":"微辣",' +
                '"DESCRIPTION":"描述1"' +
                '}}';
            ws.send(sendJson);
        }








        function consumerLogin(){
            // 顾客登录
            var param1 = $("#params1").val();
            var sendJson = '{"ActionType":"event_consumer_login","DataDictionary":{"WX_ID":"open_id_1"}}';
            ws.send(sendJson);
        }

        function consumerOrderNew(){
            // 顾客下单
            var param1 = $("#params1").val();
            var sendJson = '{"ActionType":"event_consumer_order_new","DataDictionary":{' +
                '"RESTAURANT_ID":"1",' +
                '"TABLE_NUMBER":"1",' +
                '"IS_TAKE_OUT":"0",' +
                '"order_for_food":{' +
                '"1":"2","2":"3"}' +
                '""' +
                '}}';
            ws.send(sendJson);
        }



    </script>
</head>
<body onload="display();">
<div id="valueLabel"></div>
<textarea rows="20" cols="30" id="contentId"></textarea>
<br/>

<!--<button id="sendButton" onClick="javascript:sendMsg()" >Send</button>-->

参数1:<input id = "params1" name="params1">
<!--参数2:<input id = "params2" name="params2">-->
<!--参数3:<input id = "params3" name="params3">-->
<!--参数4:<input id = "params4" name="params4">-->
<!--参数5:<input id = "params5" name="params5">-->
<!--参数6:<input id = "params6" name="params6">-->
<!--参数7:<input id = "params7" name="params7">-->
<!--参数8:<input id = "params8" name="params8">-->
<!--参数9:<input id = "params9" name="params9">-->
<!--参数10:<input id = "params10" name="params10">-->
<!--参数11:<input id = "params11" name="params11">-->
<!--参数12:<input id = "params12" name="params12">-->
<!--参数13:<input id = "params13" name="params13">-->
<!--参数14:<input id = "params14" name="params14">-->
<!--参数15:<input id = "params15" name="params15">-->
<!--参数16:<input id = "params16" name="params16">-->
<!--参数17:<input id = "params17" name="params17">-->
<!--参数18:<input id = "params18" name="params18">-->
<!--参数19:<input id = "params19" name="params19">-->
<!--参数20:<input id = "params20" name="params20">-->
<!--参数21:<input id = "params21" name="params21">-->
<!--参数22:<input id = "params22" name="params22">-->


<br>
<br>

商家 <br>
<button id="sendButton" onClick="javascript:test()">测试通讯 1:传递值</button>

<button id="sendButton" onClick="javascript:restaurantAdd()">商铺添加</button>
<button id="sendButton" onClick="javascript:restaurantLogin()">商家登录</button>
<button id="sendButton" onClick="javascript:restaurantFoodGroupsAdd()">商家添加商品分类</button>
<button id="sendButton" onClick="javascript:restaurantFoodAdd()">商家添加商品</button>



<br>
<br>
<p>顾客</p>
<button id="sendButton" onClick="javascript:consumerLogin()">顾客登录</button>
<button id="sendButton" onClick="javascript:consumerOrderNew()">顾客下单</button>

</body>
</html>
